// 2025/09/24
// Author: Forever
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m, res, a[1000001], cnt[1000001], now_cnt[1000001], ok, opt[1000001][2];

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
        cin >> opt[i][0];
    for (int i = 1; i <= m; i++)
        cin >> opt[i][1];
    for (int i = 1; i <= m; i++)
        cnt[opt[i][1]] = opt[i][0], res += opt[i][0];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    if (res > n){
        cout << 0;
        return 0;
    }
    for (int i = 1; i <= res; i++)
        now_cnt[a[i]]++;
    for (int i = 1; i <= n; i++)
        if (now_cnt[i] == cnt[i])
            ok++;
    int ans = ok == n;
    for (int i = res + 1; i <= n; i++){
        bool flag1 = (now_cnt[a[i]] == cnt[a[i]]), flag2 = (now_cnt[a[i - res]] == cnt[a[i - res]]);
        now_cnt[a[i]]++, now_cnt[a[i - res]]--;
        if (flag1 != (now_cnt[a[i]] == cnt[a[i]]))
            ok = ok + (now_cnt[a[i]] == cnt[a[i]] ? 1 : -1);
        if (flag2 != (now_cnt[a[i - res]] == cnt[a[i - res]]))
            ok = ok + (now_cnt[a[i - res]] == cnt[a[i - res]] ? 1 : -1);
        ans += (ok == n);
    }
    cout << ans << endl;
    return 0;
}

/*
12 2
ccbcbbbbbbcb
123456789ABC
*/